package com.test;

import java.sql.*;

public class MysqlDemo {
    public static void main(String[] args) throws Exception {
        Connection conn = null;
        String db_host;
        String db_port;
        String db_user;
        String db_pass;
        String db_name;
        String url;

//        db_host = "localhost";
//        db_port = "3306";
//        db_name = "shuyun";
//        db_user = "root";
//        db_pass = "1234";
        db_host = "jconnj3mj8672.mysql.rds.aliyuncs.com";
        db_port = "3306";
        db_name = "ccms6_semir";
        db_user = "jusr4gpdssyy";
        db_pass = "ldkfie8293kdFcjfsdf231";

        url = "jdbc:mysql://"
                + db_host + ":"
                + db_port + "/"
                + db_name + "?"
                + "user=" + db_user + "&"
                + "password=" + db_pass
                + "&useUnicode=true&characterEncoding=UTF8";

        try {
            Class.forName("com.mysql.jdbc.Driver");
            // or:
            // com.mysql.jdbc.Driver driver = new com.mysql.jdbc.Driver();
            // or：
            // new com.mysql.jdbc.Driver();
            conn = DriverManager.getConnection(url);
            Statement stmt = conn.createStatement();
            String sql = "";
//            sql = "insert into student(id,name) values('4','对对对')";
//            int result = stmt.executeUpdate(sql);

//            sql = "select * from config";
            sql = "select * from schedule_log_subjob where node_id = '10101102' and job_id = '12362';";
            ResultSet rs = stmt.executeQuery(sql);
            while (rs.next()) {
//                System.out.println(rs.getString(1) + "\t" + rs.getString(2));
//                rs.get
                System.out.println(rs.getString(1));
                System.out.println(rs.getString(2));
                System.out.println(rs.getString(3));
                System.out.println(rs.getString(4));
                System.out.println(rs.getString(5));
                System.out.println(rs.getString(6));
                System.out.println(rs.getString(7));
                System.out.println(rs.getString(8));
                System.out.println(rs.getString(9));
            }

        } catch (SQLException e) {
            System.out.println("MySQL操作错误！");
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            conn.close();
        }
    }
}
